package com.lmiot.xyclick.App;

import static com.xiaoyi.intentsdklibrary.Bean.TopClickType.EXIT;
import static com.xiaoyi.intentsdklibrary.Bean.TopClickType.PAUSE;
import static com.xiaoyi.intentsdklibrary.Bean.TopClickType.RESUME;
import static com.xiaoyi.intentsdklibrary.Bean.TopClickType.SHOW;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.Application;
import android.app.Dialog;
import android.app.Notification;
import android.content.BroadcastReceiver;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.PowerManager;
import android.os.Process;
import android.os.StrictMode;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lkx.liandianqinew.R;
import com.lmiot.floatviewsdklibrary.SDK.YYFloatButton;
import com.lmiot.floatviewsdklibrary.View.FloatView;
import com.lmiot.xyclick.ActionDetailBean.DetailBean;
import com.lmiot.xyclick.Activity.LoginActivity;
import com.lmiot.xyclick.Activity.MainActivity;
import com.lmiot.xyclick.Auto.AutoUtils;
import com.lmiot.xyclick.Bean.ChangeDataBean;
import com.lmiot.xyclick.Bean.ControkeyBean;
import com.lmiot.xyclick.Bean.CopyTextBean;
import com.lmiot.xyclick.Bean.DelayEndTime;
import com.lmiot.xyclick.Bean.DoAutoBean;
import com.lmiot.xyclick.Bean.InitFloatBean;
import com.lmiot.xyclick.Bean.LoginDevSuccessBean;
import com.lmiot.xyclick.Bean.MediaTypeBean;
import com.lmiot.xyclick.Bean.NetStateBean;
import com.lmiot.xyclick.Bean.ResloveViewBean;
import com.lmiot.xyclick.Bean.ResumeActivityBean;
import com.lmiot.xyclick.Bean.SQL.ActionBean;
import com.lmiot.xyclick.Bean.SQL.ActionBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.AutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.FGBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.FriendBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.GroupBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.SearchBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.VoiceSqlUtil;
import com.lmiot.xyclick.Bean.SetFloatBean;
import com.lmiot.xyclick.Bind.BindEnum;
import com.lmiot.xyclick.Bind.FloatEditActivity;
import com.lmiot.xyclick.Method.ChoseActionFourUtil;
import com.lmiot.xyclick.Method.ChoseActionUtil;
import com.lmiot.xyclick.Method.ParamUtils;
import com.lmiot.xyclick.Notic.NoticEnum;
import com.lmiot.xyclick.Notic.NoticManager;
import com.lmiot.xyclick.Thread.AutoThread;
import com.lmiot.xyclick.Util.AlarmUtil;
import com.lmiot.xyclick.Util.ClickUtils;
import com.lmiot.xyclick.Util.Constants;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.DebugUtli;
import com.lmiot.xyclick.Util.DirectUtil;
import com.lmiot.xyclick.Util.DpUtil;
import com.lmiot.xyclick.Util.FloatManager;
import com.lmiot.xyclick.Util.ImgUtil;
import com.lmiot.xyclick.Util.LayoutDialogUtil;
import com.lmiot.xyclick.Util.LkxLog;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.Util.LoopUtils;
import com.lmiot.xyclick.Util.NetworkUtils;
import com.lmiot.xyclick.Util.PhoneUtil;
import com.lmiot.xyclick.Util.RecordSDK;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import com.xiaoyi.intentsdklibrary.Bean.AppBeanSqlUtil;
import com.xiaoyi.intentsdklibrary.Bean.AsToastBean;
import com.xiaoyi.intentsdklibrary.Bean.ClickAsButtonBean;
import com.xiaoyi.intentsdklibrary.Bean.MsgBeanSqlUtil;
import com.xiaoyi.intentsdklibrary.Bean.PointBean;
import com.xiaoyi.intentsdklibrary.Bean.ShareBeanSqlUtil;
import com.xiaoyi.intentsdklibrary.Bean.TopClickType;
import com.xiaoyi.intentsdklibrary.Bean.TopClickTypeBean;
import com.xiaoyi.intentsdklibrary.Bean.TopTipBean;
import com.xiaoyi.intentsdklibrary.Bean.ViewBean;
import com.xiaoyi.intentsdklibrary.ClickViewBean;
import com.xiaoyi.intentsdklibrary.KeyClickBean;
import com.xiaoyi.intentsdklibrary.NoticTextBean;
import com.xiaoyi.intentsdklibrary.PathViewBean;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionAsSDK;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.SDK.Event.EvenSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.CirCleViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.NormalTopViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.PathViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.RectViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.TopViewSDK;
import com.xiaoyi.intentsdklibrary.SDK.FloatView.TopViewSDKShort;
import com.xiaoyi.intentsdklibrary.SDK.SDK;
import com.xiaoyi.jni.JNITest;
import com.xiaoyi.pdocrlibrary.PaddOCRSDK;
import com.yhao.floatwindow.ChangViewBean;
import com.yhao.floatwindow.ChangeViewXYBean;
import com.yhao.floatwindow.FloatUtil;
import com.yhao.floatwindow.FloatWindow;
import com.yhao.floatwindow.MoveType;
import com.youyi.yynoticlibrary.YYNoticSDK;
import com.youyi.yypermissionlibrary.SDK.OnPerListener;
import com.youyi.yypermissionlibrary.SDK.YYPerUtils;
import com.youyi.yyscreencutlibrary.ShowMainActivity;
import com.youyi.yyscreencutlibrary.Track.YYTrackSDK;
import com.youyi.yyviewsdklibrary.ArrayGson;
import com.youyi.yyviewsdklibrary.Dialog.util.BackgroundExecutor;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.YYSDK;
import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.opencv.SDK.OpenCVUtils;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.FastResultBean;

public class MyApp extends Application {
    private static final String TAG = "MyApp";
    private static MyApp instance = null;
    public static boolean isMqttConnect = false;
    public static boolean isRunningHand;
    public static boolean isRunningHandPlus;
    public static boolean isRunningTrack;
    public static AutoBean mAutoBeanNowRun;
    private static Context mContext;
    public static int mFinishNumRun;
    public static boolean mHasInit;
    public static int mHeight;
    public static OnActionViewLongClickListener mOnActionViewLongClickListener;
    public static int mWidth;
    public static OnDialogShowClickListener onDialogShowClickListener;
    private List<Activity> activityList = new LinkedList();
    private ActionBean mActionBeanNowRun;
    private AudioManager mAudioManager;
    private AutoThread mAutoThread;
    private Dialog mDialogDirect;
    private Handler mHandler;
    private Handler mHandlerListen;
    private boolean mHasSet;
    private Intent mIntent;
    private String mKeyDownFLag = "";
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int i) {
            if (i != 0) {
                super.onManagerConnected(i);
            } else {
                LogUtil.d(MyApp.TAG, "OpenCV loaded successfully");
            }
        }
    };
    private MyIntentReceive mMyReceive;
    private NetWorkReceiver mNetWorkReceiver;
    private ImageView mPauseExit;
    private View mPauseInflate;
    private ImageView mPausePause;
    private ImageView mPauseResume;
    private TextView mPauseStep;
    private TextView mPauseTip;
    private Runnable mRListen;
    private Runnable mRunnable;
    private Runtime mRuntime;
    private String mSetFlagRun;
    private TextView mText;
    private Thread mThread;
    private int mTimeNumRun;
    private Timer mTimer;
    private Timer mTimerRun;
    private TimerTask mTimerTask;
    private TimerTask mTimerTaskRun;
    private TextView mTip;
    private String mTrackPath;
    private int mTypeNowRun;
    private TextView mViewXY;
    private PowerManager.WakeLock mWakeLockRun;

    public interface OnActionViewLongClickListener {
        void result(int i, int i2);
    }

    public interface OnDialogShowClickListener {
        void result(boolean z);
    }

    static /* synthetic */ int access$1508(MyApp myApp) {
        int i = myApp.mTimeNumRun;
        myApp.mTimeNumRun = i + 1;
        return i;
    }

    public void onCreate() {
        super.onCreate();
        instance = this;
        mContext = getApplicationContext();
//        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
//        }
    }

    public void startInit() {
        if (!this.mHasSet) {
            this.mHasSet = true;
            YYSDK.getInstance().init(this);
            YYPerUtils.initContext(this);
            YYNoticSDK.getInstance().init(this);
        }
        try {
            mHasInit = true;
            SearchBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            VoiceSqlUtil.getInstance().initDbHelp(getApplicationContext());
            AutoBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            ActionBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            GroupBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            FriendBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            FGBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            AppBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            ShareBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            MsgBeanSqlUtil.getInstance().initDbHelp(getApplicationContext());
            reslovePorvideFile();
            LoadOpenCV();
            initLocalOCR();
            setWidthAndHeight();
            ZXingLibrary.initDisplayOpinion(this);
            AlarmUtil.startTimerAlarm();
            if (!DebugUtli.isDebugVersion(getInstance())) {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        JNITest.xyInit(MyApp.getContext());
                    }
                }, 0);
            }
            setListenKey();
            reginstReceive();
            wakeLock();
            showNotic();
            registNetWord();
            initOkHttp();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    private void initOkHttp() {
        OkHttpUtils.initClient(new OkHttpClient.Builder().writeTimeout(OkHttpUtils.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS).connectTimeout(OkHttpUtils.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS).readTimeout(OkHttpUtils.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS).build());
    }

    /**
     * 保持设备
     */
    private void wakeLock() {
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        // PARTIAL_WAKE_LOCK 仅保持 CPU 唤醒
        PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyApp::MyWakeLockTag");
        wakeLock.acquire(); // 开始保持设备唤醒
    }

    private void initLocalOCR() {
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                PaddOCRSDK.getInstance().initModel(getContext(), new PaddOCRSDK.OnOcrModelInitListener() {
                    @Override
                    public void result(boolean z, String str) {
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private String getCurProcessName(Context context) {
        int myPid = Process.myPid();
        for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses()) {
            if (runningAppProcessInfo.pid == myPid) {
                return runningAppProcessInfo.processName;
            }
        }
        return "";
    }

    public static Context getContext() {
        return mContext;
    }

    private void setWidthAndHeight() {
        Display defaultDisplay = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        mHeight = defaultDisplay.getHeight();
        mWidth = defaultDisplay.getWidth();
    }

    private void LoadOpenCV() {
        if (!OpenCVLoader.initDebug()) {
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, this.mLoaderCallback);
        } else {
            this.mLoaderCallback.onManagerConnected(0);
        }
    }

    public static MyApp getInstance() {
        return instance;
    }

    public void addActivity(Activity activity) {
        this.activityList.add(activity);
    }

    public void removeActivity(Activity activity) {
        try {
            this.activityList.remove(activity);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exit() {
        try {
            for (Activity activity : this.activityList) {
                activity.finish();
            }
            YYNoticSDK.getInstance().destroy();
            stopTimerRun();
            EventBus.getDefault().unregister(this);
            this.mWakeLockRun.release();
            if (YYTrackSDK.getInstance().isRecording()) {
                YYTrackSDK.getInstance().destroyRecording(new YYTrackSDK.OnDestroyRecordListener() {
                    @Override
                    public void result(boolean z, String str) {
                    }
                });
            }
            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void startThread(String str, AutoBean autoBean, ActionBean actionBean, int i, int i2) {
        mFinishNumRun = i2;
        AutoThread autoThread = new AutoThread(str, autoBean, actionBean, i);
        this.mAutoThread = autoThread;
        autoThread.start();
    }

    public void pauseThread() {
        AutoThread autoThread = this.mAutoThread;
        if (autoThread != null) {
            autoThread.pauseThread();
        }
    }

    public void resumeThread() {
        AutoThread autoThread = this.mAutoThread;
        if (autoThread != null) {
            autoThread.resumeThread();
        }
    }

    public void stopThread() {
        try {
            AutoThread autoThread = this.mAutoThread;
            if (autoThread != null) {
                autoThread.stopThread();
            }
            stopTimer();
        } catch (Exception e) {
            e.printStackTrace();
        } catch (Throwable th) {
            this.mAutoThread = null;
            throw th;
        }
        this.mAutoThread = null;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ResumeActivityBean resumeActivityBean) {
        ToastUtil.success("添加成功2！");
        if (FloatUtil.getChangeData(getContext())) {
            AutoUtils.resumeAddActivity(getContext());
        }
    }

    public void onMessageEvent(ClickAsButtonBean clickAsButtonBean){
        AutoBean uAutoBean;
        if (clickAsButtonBean.isClick()) {
            String directData = DataUtil.getDirectData(MyApp.mContext, BindEnum.AsButton.getType());
            if (TextUtils.isEmpty(directData)) {
                if (!FloatUtil.getFloatJump(MyApp.getContext())) {
                    return;
                }else {
                    ToastUtil.warning(MyApp.mContext.getString(R.string.not_e_p));
                    Intent intent = new Intent(MyApp.mContext, FloatEditActivity.class);
                    this.mIntent = intent;
                    intent.putExtra("title", "无障碍小人按钮");
                    this.mIntent.putExtra("actionFlag", BindEnum.AsButton.toString());
                    this.mIntent.addFlags(0x10000000);
                    MyApp.mContext.startActivity(this.mIntent);
                }
            }else {
                boolean b = true;
                SDK.isRunning = b;
                ActionAsSDK.getInstance().init(MyApp.getContext());
                ActionBean uActionBean = new ArrayGson().fromJson(directData, ActionBean.class);
                if (uActionBean.getActionType().equals("key_auto")) {
                    if ((uAutoBean = AutoBeanSqlUtil.getInstance().searchByID(new ArrayGson().fromJson(uActionBean.getDetail(), DetailBean.class).getAutoID())) != null) {
                        EventBus.getDefault().post(new DoAutoBean(101, uAutoBean, null, 0));
                    }
                }else {
                    String actionType = uActionBean.getActionType();
                    actionType.hashCode();
                    int a = 0;
                    switch (actionType.hashCode()){
                        case 0x1274b125:
                            if (actionType.equals("key_now_auto_list")) {
                                a = 0;
                            }
                            break;
                        case 0x513fe36a:
                            if (actionType.equals("key_resume_now_auto")) {
                            }
                            break;
                        case 0x53640781:
                            if (actionType.equals("key_pause_now_auto")) {
                                a = 2;
                            }
                            break;
                        case 0x78a8ab35:
                            if (actionType.equals("key_stop_now_auto")) {
                                a = 3;
                            }
                            break;
                        default:
                            a = -1;
                    }
                    switch (a){
                        case 0:
                            LayoutDialogUtil.showAutoList(MyApp.getContext());
                            break;
                        case 1:
                            EventBus.getDefault().post(new DoAutoBean(103, null, null, 0));
                            break;
                        case 2:
                            EventBus.getDefault().post(new DoAutoBean(102, null, null, 0));
                            break;
                        case 3:
                            EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                            break;
                        default:
                            EventBus.getDefault().post(new DoAutoBean(105, null, uActionBean, 0));
                    }
                }
            }
        }
        return;
    }

    private void reslovePorvideFile() {
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        if (Build.VERSION.SDK_INT >= 24) {
            builder.detectFileUriExposure();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(InitFloatBean initFloatBean) {
        LkxLog.d("InitFloatBean:" + initFloatBean.getFloatType());

        switch (initFloatBean.getFloatType()) {
            case action:
                setActionView();
                return;
            case hand:
                setFloatViewClick();
                return;
            case handPlus:
                setFloatViewClickPlus();
                return;
            case track:
                setTrackViewClick();
                return;
            case record:
                RecordSDK.getInstance().initRecordView();
                return;
            case pause:
                setFloatViewPause();
                return;
            case swipPlus:
                setFloatViewListener();
                return;
            default:
                return;
        }
    }

    private void setActionView() {
        LkxLog.d("初始化ActionView");
        View inflate = View.inflate(getContext(), R.layout.layout_action, null);
        int floatPointWidth = getFloatPointWidth();
        this.mViewXY = (TextView) inflate.findViewById(R.id.id_view_xy);
        int floatX = (int) FloatUtil.getFloatX(getContext(), "actionView");
        int floatY = (int) FloatUtil.getFloatY(getContext(), "actionView");
        this.mViewXY.setText(floatX + "," + floatY);
        FloatWindow.with(getApplicationContext()).setView(inflate).setTag("actionView").setWidth(floatPointWidth).setHeight(floatPointWidth).setMoveType(3).setDesktopShow(true).setMoveStyle(500L, new AccelerateInterpolator()).build();
        if (FloatWindow.get("actionView") != null) {
            FloatWindow.get("actionView").hide();
        }
        inflate.setOnClickListener(new View.OnClickListener() { // from class: com.lmiot.xyclick.App.MyApp.6
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                MyApp.this.showChosDialog();
            }
        });
        inflate.setOnLongClickListener(new View.OnLongClickListener() { // from class: com.lmiot.xyclick.App.MyApp.7
            @Override // android.view.View.OnLongClickListener
            public boolean onLongClick(View view) {
                if (MyApp.mOnActionViewLongClickListener == null) {
                    return true;
                }
                ClickUtils.onlyVibrate(MyApp.getContext());
                MyApp.mOnActionViewLongClickListener.result((int) FloatUtil.getFloatX(MyApp.getContext(), "actionView"), (int) FloatUtil.getFloatY(MyApp.getContext(), "actionView"));
                return true;
            }
        });
//            inflate.setVisibility(View.GONE);
    }

    private int getFloatPointWidth() {
        return DpUtil.dip2px(getContext(), (float) (((FloatUtil.getFloatPoint(getContext()) * 30) / 100) + 20));
    }

    private void setFloatViewClick() {
        try {
            View inflate = View.inflate(getContext(), R.layout.layout_float_click, null);
            FloatWindow.with(getApplicationContext()).setView(inflate).setTag("floatViewClick").setWidth(DpUtil.dip2px(getContext(), 50.0f)).setHeight(DpUtil.dip2px(getContext(), 50.0f)).setMoveType(MoveType.slide).setDesktopShow(true).setMoveStyle(500, new AccelerateInterpolator()).build();
            inflate.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    MyApp.this.showChosDialogClick();
                }
            });
            inflate.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setFloatViewPause() {
        try {
            FloatWindow.destroy("floatViewPause");
            this.mPauseInflate = View.inflate(getContext(), R.layout.layout_float_pause, null);
            FloatWindow.with(getApplicationContext()).setView(this.mPauseInflate).setTag("floatViewPause").setMoveType(MoveType.slide).setDesktopShow(true).setMoveStyle(500, new AccelerateInterpolator()).build();
            this.mPausePause = (ImageView) this.mPauseInflate.findViewById(R.id.id_pause);
            this.mPauseResume = (ImageView) this.mPauseInflate.findViewById(R.id.id_play);
            this.mPauseExit = (ImageView) this.mPauseInflate.findViewById(R.id.id_exit);
            this.mPauseTip = (TextView) this.mPauseInflate.findViewById(R.id.id_tip);
            this.mPauseStep = (TextView) this.mPauseInflate.findViewById(R.id.id_step);
            this.mPausePause.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    MyApp.this.mPausePause.setVisibility(View.GONE);
                    MyApp.this.mPauseResume.setVisibility(View.VISIBLE);
                    EventBus.getDefault().post(new TopClickTypeBean(PAUSE, ""));
                }
            });
            this.mPausePause.setOnLongClickListener(new View.OnLongClickListener() {
                public boolean onLongClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    MyApp.this.mPausePause.setVisibility(View.GONE);
                    MyApp.this.mPauseResume.setVisibility(View.VISIBLE);
                    EventBus.getDefault().post(new TopClickTypeBean(PAUSE, ""));
                    return true;
                }
            });
            this.mPauseResume.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    MyApp.this.mPauseResume.setVisibility(View.GONE);
                    MyApp.this.mPausePause.setVisibility(View.VISIBLE);
                    EventBus.getDefault().post(new TopClickTypeBean(RESUME, ""));
                }
            });
            this.mPauseResume.setOnLongClickListener(new View.OnLongClickListener() {
                public boolean onLongClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    MyApp.this.mPauseResume.setVisibility(View.GONE);
                    MyApp.this.mPausePause.setVisibility(View.VISIBLE);
                    EventBus.getDefault().post(new TopClickTypeBean(RESUME, ""));
                    return true;
                }
            });
            this.mPauseExit.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    EventBus.getDefault().post(new TopClickTypeBean(EXIT, ""));
                }
            });
            this.mPauseExit.setOnLongClickListener(new View.OnLongClickListener() {
                public boolean onLongClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    EventBus.getDefault().post(new TopClickTypeBean(EXIT, ""));
                    return true;
                }
            });
            mPauseInflate.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setTrackViewClick() {
        try {
            FloatWindow.destroy("trackViewClick");
            View inflate = View.inflate(getContext(), R.layout.layout_track_click, null);
            FloatWindow.with(getApplicationContext()).setView(inflate).setTag("trackViewClick").setWidth(DpUtil.dip2px(getContext(), 50.0f)).setHeight(DpUtil.dip2px(getContext(), 50.0f)).setMoveType(MoveType.slide).setDesktopShow(true).setMoveStyle(500, new AccelerateInterpolator()).build();
            inflate.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.App.MyApp.AnonymousClass15 */

                public void onClick(View view) {
                    MyApp.this.showChosDialogTrack();
                }
            });
            inflate.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showChosDialogClick() {
        LayoutDialogUtil.showClickHandDialog(false, getContext(), "温馨提示", "开启后，屏幕会疯狂点击小手所在位置； \n\n您需要长按音量-或手机黑屏才可以停止。\n\n【再次提醒】:长按音量-、手机黑屏可停止！！\n\n您是否要无限点击当前坐标吗？", true, true, "取消", "确定", new LayoutDialogUtil.OnResultClickListener() {
            /* class com.lmiot.xyclick.App.MyApp.AnonymousClass16 */

            @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
            public void result(boolean z) {
                if (z) {
                    ClickUtils.Click(MyApp.getContext());
                    if (ActionAsSDK.getInstance().checkAs(MyApp.getContext())) {
                        MyApp.isRunningHand = true;
                        FloatManager.hide(InitFloatBean.FloatType.hand);
                        if (MyApp.this.mHandler == null) {
                            MyApp.this.mHandler = new Handler();
                        }
                        MyApp.this.mHandler.postDelayed(new Runnable() {
                            public void run() {
                                float floatX = FloatUtil.getFloatX(MyApp.getContext(), "floatViewClick");
                                float floatY = FloatUtil.getFloatY(MyApp.getContext(), "floatViewClick");
                                ActionBean actionBean = new ActionBean();
                                actionBean.setActionID("999999912324214");
                                StringBuilder sb = new StringBuilder();
                                sb.append("无限点击坐标：");
                                int i = (int) floatX;
                                sb.append(i);
                                sb.append(",");
                                int i2 = (int) floatY;
                                sb.append(i2);
                                actionBean.setActionName(sb.toString());
                                actionBean.setActionType(Constants.ACTION_TYPE_RES_CLICK_TIMES_HAND);
                                actionBean.setDelay(1);
                                actionBean.setEnable(true);
                                actionBean.setSortNum(0);
                                DetailBean detailBean = new DetailBean();
                                detailBean.setRepeat(-1);
                                detailBean.setPointBean(new PointBean(i, i2));
                                actionBean.setDetail(new Gson().toJson(detailBean));
                                EventBus.getDefault().post(new DoAutoBean(105, null, actionBean, 0));
                            }
                        }, 500);
                        return;
                    }
                    try {
                        ToastUtil.warning("请先开启无障碍权限！");
                        MyApp.this.mIntent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
                        MyApp.this.mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        MyApp myApp = MyApp.this;
                        myApp.startActivity(myApp.mIntent);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }, true);
    }

    private void showChosDialogTrack() {
        File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp");
        if (!file.exists()) {
            file.mkdir();
        }
        this.mTrackPath = "";
        File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", "track_icon.png");
        if (!file2.exists()) {
            this.mTrackPath = ImgUtil.saveBitmpToFile(BitmapFactory.decodeResource(getResources(), R.drawable.track_wx), "track_icon");
        } else {
            this.mTrackPath = file2.getAbsolutePath();
        }
        LayoutDialogUtil.showTrackDialog(getContext(), this.mTrackPath, "温馨提示", "您是否要跟踪并点击当前图标？\n\n【注】:默认长按音量-可以停止！！！", true, true, "取消", "确定", new LayoutDialogUtil.OnResultClickListener() {

            @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
            public void result(boolean z) {
                if (z) {
                    ClickUtils.Click(MyApp.getContext());
                    if (ActionAsSDK.getInstance().checkAs(MyApp.getContext())) {
                        try {
                            MyApp.isRunningTrack = true;
                            FloatManager.hide(InitFloatBean.FloatType.track);
                            if (MyApp.this.mHandler == null) {
                                MyApp.this.mHandler = new Handler();
                            }
                            MyApp.this.mHandler.postDelayed(new Runnable() {
                                /* class com.lmiot.xyclick.App.MyApp.AnonymousClass17.AnonymousClass1 */

                                public void run() {
                                    SDK.isRunning = true;
                                    ActionAsSDK.getInstance().init(MyApp.getContext());
                                    EventBus.getDefault().post(new TopTipBean("正在实时监测目标图片"));
                                    MyApp.this.startTimer();
                                }
                            }, 500);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        try {
                            ToastUtil.warning("请先开启无障碍权限！");
                            MyApp.this.mIntent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
                            MyApp.this.mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            MyApp myApp = MyApp.this;
                            myApp.startActivity(myApp.mIntent);
                        } catch (Exception e2) {
                            e2.printStackTrace();
                        }
                    }
                }
            }
        }, true);
    }

    private void setFloatViewListener() {
        if (FloatUtil.getShowFlow(getContext())) {
            YYFloatButton.show(getContext());
        }
        YYFloatButton.setmOnDirectListenerRightTime(new YYFloatButton.OnDirectListenerRightTime() {
            /* class com.lmiot.xyclick.App.MyApp.AnonymousClass18 */

            @Override // com.lmiot.floatviewsdklibrary.SDK.YYFloatButton.OnDirectListenerRightTime
            public void result(boolean z, FloatView.Mode mode) {
                BindEnum bindEnum;
                String str;
                switch (mode.ordinal()) {
                    case 1:
                        bindEnum = BindEnum.FloatClick;
                        break;
                    case 2:
                        bindEnum = BindEnum.FloatLeft;
                        break;
                    case 3:
                        bindEnum = BindEnum.FloatRight;
                        break;
                    case 4:
                        bindEnum = BindEnum.FloatUp;
                        break;
                    case 5:
                        bindEnum = BindEnum.FloatDown;
                        break;
                    case 6:
                        return;
                    default:
                        bindEnum = null;
                        break;
                }
                if (bindEnum != null) {
                    String directData = DataUtil.getDirectData(MyApp.getContext(), bindEnum.getType());
                    if (TextUtils.isEmpty(directData)) {
                        str = MyApp.this.getString(R.string.not_edit);
                    } else {
                        str = ((ActionBean) new ArrayGson().fromJson(directData, ActionBean.class)).getActionName();
                    }
                    if (!z) {
                        MyApp.this.showAlretDialog(bindEnum.getName(), str);
                        return;
                    }
                    if (MyApp.this.mDialogDirect != null) {
                        if (MyApp.this.mDialogDirect.isShowing()) {
                            MyApp.this.mDialogDirect.dismiss();
                        }
                        MyApp.this.mDialogDirect = null;
                    }
                    if (bindEnum != null) {
                        DirectUtil.resloveAction(MyApp.getContext(), bindEnum.getType());
                    }
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showAlretDialog(String str, String str2) {
        try {
            if (this.mDialogDirect == null) {
                Dialog dialog = new Dialog(getContext());
                this.mDialogDirect = dialog;
                dialog.requestWindowFeature(1);
                this.mDialogDirect.setContentView(R.layout.dialog_top_tip);
                this.mTip = (TextView) this.mDialogDirect.findViewById(R.id.id_top_tip);
                Window window = this.mDialogDirect.getWindow();
                WindowManager.LayoutParams attributes = window.getAttributes();
                window.setGravity(48);
                if (YYPerUtils.hasOp()) {
                    if (Build.VERSION.SDK_INT >= 26) {
                        window.setType(2038);
                    } else {
                        window.setType(2003);
                    }
                }
                attributes.width = -1;
                attributes.height = -2;
                window.setAttributes(attributes);
            }
            if (this.mTip == null) {
                this.mTip = (TextView) this.mDialogDirect.findViewById(R.id.id_top_tip);
            }
            TextView textView = this.mTip;
            textView.setText(str + ":" + str2);
            this.mDialogDirect.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showChosDialog() {
        ClickUtils.onlyVibrate(this);
        ChoseActionUtil.getInstance().showChoseDialog();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(TopClickTypeBean topClickTypeBean) {
        TopClickType i = topClickTypeBean.getTopClickType();
        if (i == PAUSE) {
            try {
                ImageView imageView = this.mPausePause;
                if (imageView != null) {
                    imageView.setVisibility(View.GONE);
                }
                ImageView imageView2 = this.mPauseResume;
                if (imageView2 != null) {
                    imageView2.setVisibility(View.VISIBLE);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            pauseAuto();
        } else if (i == RESUME) {
            try {
                ImageView imageView3 = this.mPauseResume;
                if (imageView3 != null) {
                    imageView3.setVisibility(View.GONE);
                }
                ImageView imageView4 = this.mPausePause;
                if (imageView4 != null) {
                    imageView4.setVisibility(View.VISIBLE);
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            resumeAuto();
        } else if (i == EXIT) {
            try {
                View view = this.mPauseInflate;
                if (view != null) {
                    view.setVisibility(View.GONE);
                }
            } catch (Exception e3) {
                e3.printStackTrace();
            }
            FloatManager.hide(InitFloatBean.FloatType.pause);
            stopAutoRun();
        } else if (i == SHOW) {
            try {
                View view2 = this.mPauseInflate;
                if (view2 != null) {
                    view2.setVisibility(View.VISIBLE);
                }
                if (!SDK.pause) {
                    ImageView imageView5 = this.mPauseResume;
                    if (imageView5 != null) {
                        imageView5.setVisibility(View.GONE);
                    }
                    ImageView imageView6 = this.mPausePause;
                    if (imageView6 != null) {
                        imageView6.setVisibility(View.VISIBLE);
                    }
                } else {
                    ImageView imageView7 = this.mPauseResume;
                    if (imageView7 != null) {
                        imageView7.setVisibility(View.VISIBLE);
                    }
                    ImageView imageView8 = this.mPausePause;
                    if (imageView8 != null) {
                        imageView8.setVisibility(View.GONE);
                    }
                }
                TextView textView = this.mPauseTip;
                if (textView != null) {
                    textView.setText(topClickTypeBean.getMsg());
                }
                if (this.mPauseStep != null) {
                    int i2 = SDK.nowNum + 1;
                    int i3 = SDK.allNum;
                    if (i2 >= i3) {
                        TextView textView2 = this.mPauseStep;
                        textView2.setText("（" + i3 + "/" + i3 + "）");
                    } else {
                        TextView textView3 = this.mPauseStep;
                        textView3.setText("（" + i2 + "/" + i3 + "）");
                    }
                }
            } catch (Exception e4) {
                e4.printStackTrace();
            }
            FloatManager.show(InitFloatBean.FloatType.pause);
        }
    }

    private void setFloatViewClickPlus() {
        int i = 0;
        while (i < 10) {
            try {
                FloatWindow.destroy("floatViewClickPlus" + i);
                View inflate = View.inflate(getContext(), R.layout.layout_float_click_plus, null);
                StringBuilder sb = new StringBuilder();
                int i2 = i + 1;
                sb.append(i2);
                sb.append("");
                ((TextView) inflate.findViewById(R.id.id_float_num)).setText(sb.toString());
                FloatWindow.B view = FloatWindow.with(getApplicationContext()).setView(inflate);
                view.setTag("floatViewClickPlus" + i).setMoveType(MoveType.slide).setDesktopShow(true).setMoveStyle(500, new AccelerateInterpolator()).build();
                inflate.setOnClickListener(new View.OnClickListener() {
                    /* class com.lmiot.xyclick.App.MyApp.AnonymousClass19 */

                    public void onClick(View view) {
                        MyApp.this.showChosDialogClickPlus();
                    }
                });
                i = i2;
                inflate.setVisibility(View.GONE);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        }
    }

    private void showChosDialogClickPlus() {
        LayoutDialogUtil.showClickHandDialog(true, getContext(), "温馨提示", "开启后，屏幕会疯狂点击小手所在位置； \n\n您需要长按音量-或手机黑屏才可以停止。\n\n【再次提醒】:长按音量-、手机黑屏可停止！！\n\n您是否要无限点击当前坐标吗？", true, true, "取消", "确定", new LayoutDialogUtil.OnResultClickListener() {
            /* class com.lmiot.xyclick.App.MyApp.AnonymousClass20 */

            @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
            public void result(boolean z) {
                if (z) {
                    ClickUtils.Click(MyApp.getContext());
                    if (ActionAsSDK.getInstance().checkAs(MyApp.getContext())) {
                        DataUtil.nowActionBeanList.clear();
                        for (int i = 0; i < 10; i++) {
                            FloatUtil.getShowFlowClickPlus(MyApp.getContext(), i);
                            if (FloatUtil.getShowFlowClickPlus(MyApp.getContext(), i)) {
                                Context context = MyApp.getContext();
                                int floatX = (int) FloatUtil.getFloatX(context, "floatViewClickPlus" + i);
                                Context context2 = MyApp.getContext();
                                int floatY = (int) FloatUtil.getFloatY(context2, "floatViewClickPlus" + i);
                                ActionBean actionBean = new ActionBean();
                                actionBean.setActionID("999999912324214" + i);
                                actionBean.setActionName("点击坐标：" + floatX + "," + floatY);
                                actionBean.setActionType(Constants.ACTION_TYPE_RES_CLICK_TIMES_HAND);
                                actionBean.setEnable(true);
                                actionBean.setSortNum(i);
                                DetailBean detailBean = new DetailBean();
                                detailBean.setRepeat(1);
                                detailBean.setPointBean(new PointBean(floatX, floatY));
                                actionBean.setDetail(new Gson().toJson(detailBean));
                                actionBean.setDelay(DataUtil.getHandClickTime(MyApp.getContext()));
                                DataUtil.nowActionBeanList.add(actionBean);
                            }
                        }
                        MyApp.isRunningHandPlus = true;
                        FloatManager.hide(InitFloatBean.FloatType.handPlus);
                        if (MyApp.this.mHandler == null) {
                            MyApp.this.mHandler = new Handler();
                        }
                        MyApp.this.mHandler.postDelayed(new Runnable() {
                            /* class com.lmiot.xyclick.App.MyApp.AnonymousClass20.AnonymousClass1 */

                            public void run() {
                                EventBus.getDefault().post(new DoAutoBean(109, null, null, 0));
                            }
                        }, 500);
                        return;
                    }
                    try {
                        ToastUtil.warning("请先开启无障碍权限！");
                        MyApp.this.mIntent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
                        MyApp.this.mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        MyApp myApp = MyApp.this;
                        myApp.startActivity(myApp.mIntent);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }, true);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ChangViewBean changViewBean) {
        String viewName = changViewBean.getViewName();
        viewName.hashCode();
        if (viewName.equals("actionView") && FloatWindow.get("actionView") != null) {
            FloatWindow.get("actionView").updateX(getFloatPointWidth(), getFloatPointWidth());
        }
    }

    private void showNotic() {
        if (NoticManager.getNoticValue(getContext(), NoticEnum.FloatNotic)) {
            NoticManager.getInstance().show(NoticEnum.FloatNotic);
        }
        NoticManager.getInstance().updateAutoNotic();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(SetFloatBean setFloatBean) {
        InitFloatBean.FloatType floatType = setFloatBean.getFloatType();
        int i = 0;
        if (setFloatBean.isShow()) {
            switch (floatType) {
                case action:
                    FloatUtil.setEdit(true);
                    if (FloatWindow.get("actionView") != null) {
                        FloatWindow.get("actionView").show();
                        return;
                    } else {
                        EventBus.getDefault().post(new InitFloatBean(floatType));
                        return;
                    }
                case hand:
                    FloatUtil.setShowFlowClick(getContext(), true);
                    if (FloatWindow.get("floatViewClick") != null) {
                        FloatWindow.get("floatViewClick").show();
                        return;
                    } else {
                        EventBus.getDefault().post(new InitFloatBean(floatType));
                        return;
                    }
                case handPlus:
                    break;
                case track:
                    FloatUtil.setShowTrackClick(getContext(), true);
                    if (FloatWindow.get("trackViewClick") != null) {
                        FloatWindow.get("trackViewClick").show();
                        return;
                    } else {
                        EventBus.getDefault().post(new InitFloatBean(floatType));
                        return;
                    }
                case record:
                    FloatUtil.setShowRecord(true);
                    if (FloatWindow.get("floatViewRecord") != null) {
                        FloatWindow.get("floatViewRecord").show();
                        return;
                    } else {
                        EventBus.getDefault().post(new InitFloatBean(floatType));
                        return;
                    }
                case pause:
                    FloatUtil.setShowPause(true);
                    if (FloatWindow.get("floatViewPause") != null) {
                        FloatWindow.get("floatViewPause").show();
                        return;
                    } else {
                        EventBus.getDefault().post(new InitFloatBean(floatType));
                        return;
                    }
                case menu:
                case swipPlus:
                    FloatUtil.setSwipe(true);
                    if (FloatWindow.get("swipeView") != null) {
                        FloatWindow.get("swipeView").show();
                        return;
                    }
                default:
                    return;
            }
            while (i < 10) {
                if (FloatWindow.get("floatViewClickPlus" + i) != null && FloatUtil.getShowFlowClickPlus(getContext(), i)) {
                    FloatWindow.get("floatViewClickPlus" + i).show();
                }
                i++;
            }
            return;
        }

        switch (floatType) {
            case action:
                FloatUtil.setEdit(false);
                if (FloatWindow.get("actionView") != null) {
                    FloatWindow.get("actionView").hide();
                    break;
                }
                break;
            case hand:
                FloatUtil.setShowFlowClick(getContext(), false);
                if (FloatWindow.get("floatViewClick") != null) {
                    FloatWindow.get("floatViewClick").hide();
                    break;
                }
                break;
            case handPlus:
                for (int i2 = 0; i2 < 10; i2++) {
                    FloatUtil.setShowFlowClickPlus(getContext(), i2, false);
                }
                while (i < 10) {
                    if (FloatWindow.get("floatViewClickPlus" + i) != null) {
                        FloatWindow.get("floatViewClickPlus" + i).hide();
                    }
                    i++;
                }
                break;
            case track:
                FloatUtil.setShowTrackClick(getContext(), false);
                if (FloatWindow.get("trackViewClick") != null) {
                    FloatWindow.get("trackViewClick").hide();
                    break;
                }
                break;
            case record:
                FloatUtil.setShowRecord(false);
                if (FloatWindow.get("floatViewRecord") != null) {
                    FloatWindow.get("floatViewRecord").hide();
                    break;
                }
                break;
            case pause:
                FloatUtil.setShowPause(false);
                if (FloatWindow.get("floatViewPause") != null) {
                    FloatWindow.get("floatViewPause").hide();
                    break;
                }
                break;
            case swipPlus:
                FloatUtil.setSwipe(false);
                if (FloatWindow.get("swipeView") != null) {
                    FloatWindow.get("swipeView").hide();
                    break;
                }
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MediaTypeBean mediaTypeBean) {
        if (this.mRuntime == null) {
            this.mRuntime = Runtime.getRuntime();
        }
        if (this.mAudioManager == null) {
            this.mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        }
        try {
            switch (mediaTypeBean.getMediaType().ordinal()) {
                case 1:
                    this.mRuntime.exec("input keyevent 126");
                    return;
                case 2:
                    this.mRuntime.exec("input keyevent 85");
                    return;
                case 3:
                    this.mRuntime.exec("input keyevent 87");
                    return;
                case 4:
                    this.mRuntime.exec("input keyevent 88");
                    return;
                case 5:
                    this.mAudioManager.adjustStreamVolume(3, 1, 1);
                    return;
                case 6:
                    this.mAudioManager.adjustStreamVolume(3, -1, 1);
                    return;
                default:
                    return;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void startTimer() {
        stopTimer();
        this.mTimer = new Timer();
        TimerTask r2 = new TimerTask() {
            public void run() {
                if (MyApp.isRunningTrack) {
                    try {
                        FastResultBean findOneTarget = OpenCVUtils.findOneTarget(LoopUtils.trackFull(), BitmapFactory.decodeFile(MyApp.this.mTrackPath));
                        if (findOneTarget != null) {
                            if (findOneTarget.getLikeNum() >= DataUtil.getTrackClick(MyApp.getContext())) {
                                EventBus.getDefault().post(findOneTarget);
                                EventBus eventBus = EventBus.getDefault();
                                eventBus.post(new TopTipBean("发现目标图片，相似度：" + findOneTarget.getLikeNum()));
                                ActionAsSDK.getInstance().clickXY(findOneTarget.getX() + (findOneTarget.getWidth() / 2), findOneTarget.getY() + (findOneTarget.getHeight() / 2));
                                return;
                            }
                            EventBus eventBus2 = EventBus.getDefault();
                            eventBus2.post(new TopTipBean("图片相似度不足：" + findOneTarget.getLikeNum()));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        this.mTimerTask = r2;
        this.mTimer.schedule(r2, 1000, 1000);
    }

    private void stopTimer() {
        try {
            TimerTask timerTask = this.mTimerTask;
            if (timerTask != null) {
                timerTask.cancel();
                this.mTimerTask = null;
            }
            Timer timer = this.mTimer;
            if (timer != null) {
                timer.cancel();
                this.mTimer = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ChangeViewXYBean changeViewXYBean) {
        try {
            if (changeViewXYBean.getTag().equals("actionView") && FloatUtil.getViewXY(this)) {
                TextView textView = this.mViewXY;
                textView.setText(((int) FloatUtil.getFloatX(getContext(), "actionView")) + "," + ((int) FloatUtil.getFloatY(getContext(), "actionView")));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showVieXY(boolean z) {
        try {
            TextView textView = this.mViewXY;
            if (textView != null) {
                textView.setVisibility(z ? View.VISIBLE : View.GONE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ResloveViewBean resloveViewBean) {
        if (ActionAsSDK.getInstance().checkAs(getContext())) {
            NoteInfoViewSDK.getInstance().chose(getContext(), NoteInfoViewSDK.FindViewType.ALL, new NoteInfoViewSDK.OnChoseViewListener() {
                /* class com.lmiot.xyclick.App.MyApp.AnonymousClass24 */

                @Override
                // com.xiaoyi.intentsdklibrary.SDK.FloatView.NoteInfoViewSDK.OnChoseViewListener
                public void result(ViewBean viewBean, String str) {
                }
            });
        } else if (YYPerUtils.getPhoneCompany().equals("xiaomi")) {
            LayoutDialogUtil.showSureDialog(getContext(), "操作步骤", "请按以下步骤开启:\n\n无障碍>更多已下载到服务>连点器>把开关打开\n\n注：\n1.如果一直提示无法开启，请重启一次手机！\n\n2.如果提示被遮挡，请重启一次手机！", true, false, "取消", "前往开启", new LayoutDialogUtil.OnResultClickListener() {
                /* class com.lmiot.xyclick.App.MyApp.AnonymousClass22 */

                @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                public void result(boolean z) {
                    if (z) {
                        ToastUtil.warning("请找到：已下载的服务");
                        ActionNormalSDK.getInstance().gotoAsSetting(MyApp.getContext());
                    }
                }
            });
        } else {
            LayoutDialogUtil.showSureDialog(getContext(), "操作步骤", "请按以下步骤开启:\n\n无障碍>连点器>把开关打开\n\n注：\n1.如果一直提示无法开启，请重启一次手机！\n\n2.如果提示被遮挡，请重启一次手机！", true, false, "取消", "前往开启", new LayoutDialogUtil.OnResultClickListener() {
                /* class com.lmiot.xyclick.App.MyApp.AnonymousClass23 */

                @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                public void result(boolean z) {
                    if (z) {
                        ToastUtil.warning("找到连点器，然后打开");
                        ActionNormalSDK.getInstance().gotoAsSetting(MyApp.getContext());
                    }
                }
            });
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(AsToastBean asToastBean) {
        ToastUtil.warning(asToastBean.getValue());
    }

    private void setListenKey() {
        EvenSDK.getInstance().setOnKeyClickListener(new EvenSDK.OnKeyClickListener() {
            @Override
            public void onResult(KeyClickBean keyClickBean) {
                if (keyClickBean != null) {
                    switch (keyClickBean.getKeyClickType().ordinal()) {
                        case 1:
                            MyApp.this.mKeyDownFLag = DataUtil.KYE_LONG_VOLUEM_DES;
                            MyApp.this.startCheck();
                            return;
                        case 2:
                            EventBus.getDefault().post(new ControkeyBean(DataUtil.KYE_VOLUEM_DES));
                            MyApp.this.mKeyDownFLag = "";
                            return;
                        case 3:
                            MyApp.this.mKeyDownFLag = DataUtil.KYE_LONG_VOLUEM_ADD;
                            MyApp.this.startCheck();
                            return;
                        case 4:
                            EventBus.getDefault().post(new ControkeyBean(DataUtil.KYE_VOLUEM_ADD));
                            MyApp.this.mKeyDownFLag = "";
                            return;
                        case 5:
                            MyApp.this.mKeyDownFLag = DataUtil.KYE_LONG_HOME;
                            MyApp.this.startCheck();
                            return;
                        case 6:
                            MyApp.this.mKeyDownFLag = "";
                            return;
                        case 7:
                            MyApp.this.mKeyDownFLag = DataUtil.KYE_LONG_BACK;
                            MyApp.this.startCheck();
                            return;
                        case 8:
                            MyApp.this.mKeyDownFLag = "";
                            return;
                        case 9:
                            MyApp.this.mKeyDownFLag = DataUtil.KYE_LONG_RECNET;
                            MyApp.this.startCheck();
                            return;
                        case 10:
                            MyApp.this.mKeyDownFLag = "";
                            return;
                        case 11:
                            EventBus.getDefault().post(new ControkeyBean(DataUtil.KYE_LONG_BACK));
                            return;
                        case 12:
                            EventBus.getDefault().post(new ControkeyBean(DataUtil.KYE_LONG_HOME));
                            return;
                        case 13:
                            EventBus.getDefault().post(new ControkeyBean(DataUtil.KYE_LONG_RECNET));
                            return;
                        default:
                            return;
                    }
                }
            }
        });
        EvenSDK.getInstance().setOnListenNoticText(getContext(), new EvenSDK.OnNoticTextListener() {
            /* class com.lmiot.xyclick.App.MyApp.AnonymousClass26 */

            @Override // com.xiaoyi.intentsdklibrary.SDK.Event.EvenSDK.OnNoticTextListener
            public void onResult(NoticTextBean noticTextBean) {
                noticTextBean.getNoticText();
                EventBus.getDefault().post(noticTextBean);
            }
        });
        EvenSDK.getInstance().setOnScreenListener(getContext(), new EvenSDK.onScreenEventListener() {
            /* class com.lmiot.xyclick.App.MyApp.AnonymousClass27 */

            @Override // com.xiaoyi.intentsdklibrary.SDK.Event.EvenSDK.onScreenEventListener
            public void onResult(EvenSDK.ScreenType screenType) {
                if (screenType.ordinal() == 3 && FloatUtil.getLockStop(MyApp.getContext())) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void startCheck() {
        try {
            if (this.mHandlerListen == null) {
                this.mHandlerListen = new Handler();
            }
            Runnable runnable = this.mRListen;
            if (runnable != null) {
                this.mHandlerListen.removeCallbacks(runnable);
            }
            this.mRListen = null;
            Runnable r0 = new Runnable() {
                /* class com.lmiot.xyclick.App.MyApp.AnonymousClass28 */

                public void run() {
                    if (!TextUtils.isEmpty(MyApp.this.mKeyDownFLag)) {
                        EventBus.getDefault().post(new ControkeyBean(MyApp.this.mKeyDownFLag));
                    }
                }
            };
            this.mRListen = r0;
            this.mHandlerListen.postDelayed(r0, 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ControkeyBean controkeyBean) {
        char c;
        char c2;
        char c3;
        String stopAuto = FloatUtil.getStopAuto(this);
        String directData = DataUtil.getDirectData(getContext(), BindEnum.VolumeDown.getType());
        String directData2 = DataUtil.getDirectData(getContext(), BindEnum.VolumeUp.getType());
        String keyValue = controkeyBean.getKeyValue();
        keyValue.hashCode();
        switch (keyValue.hashCode()) {
            case -1945307511:
                if (keyValue.equals(DataUtil.KYE_LONG_VOLUEM_DES)) {
                    c = 0;
                    break;
                }
                c = 65535;
                break;
            case -1584530868:
                if (keyValue.equals(DataUtil.KYE_LONG_VOLUEM_ADD)) {
                    c = 1;
                    break;
                }
                c = 65535;
                break;
            case -758986233:
                if (keyValue.equals(DataUtil.KYE_LONG_HOME)) {
                    c = 2;
                    break;
                }
                c = 65535;
                break;
            case -279675091:
                if (keyValue.equals(DataUtil.KYE_VOLUEM_ADD)) {
                    c = 3;
                    break;
                }
                c = 65535;
                break;
            case 534626691:
                if (keyValue.equals(DataUtil.KYE_LONG_RECNET)) {
                    c = 4;
                    break;
                }
                c = 65535;
                break;
            case 1082991082:
                if (keyValue.equals(DataUtil.KYE_VOLUEM_DES)) {
                    c = 5;
                    break;
                }
                c = 65535;
                break;
            case 1673530895:
                if (keyValue.equals(DataUtil.KYE_LONG_BACK)) {
                    c = 6;
                    break;
                }
                c = 65535;
                break;
            default:
                c = 65535;
                break;
        }
        switch (c) {
            case 0:
                if (stopAuto.equals(DataUtil.KYE_LONG_VOLUEM_DES)) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                    return;
                }
                return;
            case 1:
                if (stopAuto.equals(DataUtil.KYE_LONG_VOLUEM_ADD)) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                    return;
                }
                return;
            case 2:
                if (stopAuto.equals(DataUtil.KYE_LONG_HOME)) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                    return;
                }
                return;
            case 3:
                if (stopAuto.equals(DataUtil.KYE_VOLUEM_ADD)) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                }
                if (!TextUtils.isEmpty(directData2)) {
                    ClickUtils.onlyVibrate(getContext());
                    SDK.isRunning = true;
                    ActionAsSDK.getInstance().init(getContext());
                    ClickUtils.onlyVibrate(getContext());
                    ActionBean actionBean = (ActionBean) new ArrayGson().fromJson(directData2, ActionBean.class);
                    if (actionBean.getActionType().equals(Constants.ACTION_TYPE_DO_INSIGN_AUTO)) {
                        AutoBean searchByID = AutoBeanSqlUtil.getInstance().searchByID(((DetailBean) new ArrayGson().fromJson(actionBean.getDetail(), DetailBean.class)).getAutoID());
                        if (searchByID != null) {
                            EventBus.getDefault().post(new DoAutoBean(101, searchByID, null, 0));
                            return;
                        }
                        return;
                    }
                    String actionType = actionBean.getActionType();
                    actionType.hashCode();
                    switch (actionType.hashCode()) {
                        case 309637413:
                            if (actionType.equals(Constants.ACTION_TYPE_AUTO_LIST)) {
                                c2 = 0;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 1363141482:
                            if (actionType.equals(Constants.ACTION_TYPE_REUSME_AUTO)) {
                                c2 = 1;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 1399064449:
                            if (actionType.equals(Constants.ACTION_TYPE_PAUSE_AUTO)) {
                                c2 = 2;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 2024319797:
                            if (actionType.equals(Constants.ACTION_TYPE_STOP_AUTO)) {
                                c2 = 3;
                                break;
                            }
                            c2 = 65535;
                            break;
                        default:
                            c2 = 65535;
                            break;
                    }
                    switch (c2) {
                        case 0:
                            LayoutDialogUtil.showAutoList(getContext());
                            return;
                        case 1:
                            EventBus.getDefault().post(new DoAutoBean(103, null, null, 0));
                            return;
                        case 2:
                            EventBus.getDefault().post(new DoAutoBean(102, null, null, 0));
                            return;
                        case 3:
                            EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                            return;
                        default:
                            EventBus.getDefault().post(new DoAutoBean(105, null, actionBean, 0));
                            return;
                    }
                } else {
                    return;
                }
            case 4:
                if (stopAuto.equals(DataUtil.KYE_LONG_RECNET)) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                    return;
                }
                return;
            case 5:
                if (onDialogShowClickListener != null) {
                    ClickUtils.onlyVibrate(getContext());
                    onDialogShowClickListener.result(true);
                }
                if (stopAuto.equals(DataUtil.KYE_VOLUEM_DES)) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                }
                if (!TextUtils.isEmpty(directData)) {
                    ClickUtils.onlyVibrate(getContext());
                    SDK.isRunning = true;
                    ActionAsSDK.getInstance().init(getContext());
                    ClickUtils.onlyVibrate(getContext());
                    ActionBean actionBean2 = (ActionBean) new ArrayGson().fromJson(directData, ActionBean.class);
                    if (actionBean2.getActionType().equals(Constants.ACTION_TYPE_DO_INSIGN_AUTO)) {
                        AutoBean searchByID2 = AutoBeanSqlUtil.getInstance().searchByID(((DetailBean) new ArrayGson().fromJson(actionBean2.getDetail(), DetailBean.class)).getAutoID());
                        if (searchByID2 != null) {
                            EventBus.getDefault().post(new DoAutoBean(101, searchByID2, null, 0));
                            return;
                        }
                        return;
                    }
                    String actionType2 = actionBean2.getActionType();
                    actionType2.hashCode();
                    switch (actionType2.hashCode()) {
                        case 309637413:
                            if (actionType2.equals(Constants.ACTION_TYPE_AUTO_LIST)) {
                                c3 = 0;
                                break;
                            }
                            c3 = 65535;
                            break;
                        case 1363141482:
                            if (actionType2.equals(Constants.ACTION_TYPE_REUSME_AUTO)) {
                                c3 = 1;
                                break;
                            }
                            c3 = 65535;
                            break;
                        case 1399064449:
                            if (actionType2.equals(Constants.ACTION_TYPE_PAUSE_AUTO)) {
                                c3 = 2;
                                break;
                            }
                            c3 = 65535;
                            break;
                        case 2024319797:
                            if (actionType2.equals(Constants.ACTION_TYPE_STOP_AUTO)) {
                                c3 = 3;
                                break;
                            }
                            c3 = 65535;
                            break;
                        default:
                            c3 = 65535;
                            break;
                    }
                    switch (c3) {
                        case 0:
                            LayoutDialogUtil.showAutoList(getContext());
                            return;
                        case 1:
                            EventBus.getDefault().post(new DoAutoBean(103, null, null, 0));
                            return;
                        case 2:
                            EventBus.getDefault().post(new DoAutoBean(102, null, null, 0));
                            return;
                        case 3:
                            EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                            return;
                        default:
                            EventBus.getDefault().post(new DoAutoBean(105, null, actionBean2, 0));
                            return;
                    }
                } else {
                    return;
                }
            case 6:
                if (stopAuto.equals(DataUtil.KYE_LONG_BACK)) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                    return;
                }
                return;
            default:
                return;
        }
    }

    private void reginstReceive() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(DataUtil.TOOL_INTENT_WX_ZXING);
        intentFilter.addAction(DataUtil.TOOL_INTENT_ZFB_ZXING);
        intentFilter.addAction(DataUtil.TOOL_INTENT_ZFB_FU);
        intentFilter.addAction(DataUtil.TOOL_INTENT_ZFB_SHOU);
        intentFilter.addAction(DataUtil.TOOL_INTENT_AUTO_LIST);
        MyIntentReceive myIntentReceive = new MyIntentReceive();
        this.mMyReceive = myIntentReceive;
        registerReceiver(myIntentReceive, intentFilter);
    }

    public class MyIntentReceive extends BroadcastReceiver {
        private MyIntentReceive() {
        }

        public void onReceive(Context context, Intent intent) {
            EventBus.getDefault().post(new ChangeDataBean(""));
            ActionNormalSDK.getInstance().closeNotification(MyApp.getContext());
            String action = intent.getAction();
            action.hashCode();
            char c = 65535;
            switch (action.hashCode()) {
                case -784748310:
                    if (action.equals(DataUtil.TOOL_INTENT_ZFB_SHOU)) {
                        c = 0;
                        break;
                    }
                    break;
                case -716829489:
                    if (action.equals(DataUtil.TOOL_INTENT_AUTO_LIST)) {
                        c = 1;
                        break;
                    }
                    break;
                case 982422142:
                    if (action.equals(DataUtil.TOOL_INTENT_ZFB_FU)) {
                        c = 2;
                        break;
                    }
                    break;
                case 1311149836:
                    if (action.equals(DataUtil.TOOL_INTENT_WX_ZXING)) {
                        c = 3;
                        break;
                    }
                    break;
                case 1449541589:
                    if (action.equals(DataUtil.TOOL_INTENT_ZFB_ZXING)) {
                        c = 4;
                        break;
                    }
                    break;
            }
            switch (c) {
                case 0:
                    ActionNormalSDK.getInstance().openZfbShou(MyApp.this);
                    return;
                case 1:
                    LayoutDialogUtil.showAutoList(MyApp.getContext());
                    return;
                case 2:
                    ActionNormalSDK.getInstance().toolZfbCode(MyApp.this);
                    return;
                case 3:
                    ActionNormalSDK.getInstance().toolWxZxing(MyApp.this);
                    return;
                case 4:
                    ActionNormalSDK.getInstance().openZfbZxing(MyApp.this);
                    return;
                default:
                    return;
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(DoAutoBean doAutoBean) {
        LkxLog.d("DoAutoBean:"+doAutoBean.getType()+"");
        switch (doAutoBean.getType()) {
            case 101:
                AutoBean autoBean = doAutoBean.getAutoBean();
                this.mTypeNowRun = 101;
                mAutoBeanNowRun = autoBean;
                startAuto(autoBean, -1, 0);
                return;
            case 102:
                TopViewSDK.getInstance().pause();
                TopViewSDKShort.getInstance().pause();
                pauseAuto();
                return;
            case 103:
                TopViewSDK.getInstance().resume();
                TopViewSDKShort.getInstance().resume();
                resumeAuto();
                return;
            case 104:
                stopAutoRun();
                return;
            case 105:
                ActionBean actionBean = doAutoBean.getActionBean();
                this.mTypeNowRun = 105;
                this.mActionBeanNowRun = actionBean;
                startAction(actionBean, -1, 0);
                return;
            case 106:
                this.mTypeNowRun = 101;
                AutoBean autoBean2 = doAutoBean.getAutoBean();
                mAutoBeanNowRun = autoBean2;
                startAuto(autoBean2, doAutoBean.getGotoNum(), mFinishNumRun);
                return;
            case 107:
                this.mTypeNowRun = 101;
                AutoBean autoBean3 = doAutoBean.getAutoBean();
                mAutoBeanNowRun = autoBean3;
                startAuto(autoBean3, -1, doAutoBean.getGotoNum());
                return;
            case 108:
                this.mTypeNowRun = 101;
                AutoBean autoBean4 = doAutoBean.getAutoBean();
                mAutoBeanNowRun = autoBean4;
                startAuto(autoBean4, doAutoBean.getGotoNum(), 0);
                return;
            case 109:
                this.mTypeNowRun = 109;
                startActionList(null, -1, 0);
                return;
            default:
                return;
        }
    }

    private void startAuto(AutoBean autoBean, int i, int i2) {
        if (DataUtil.getVip(getContext()) || !findVIPAction(autoBean)) {
            SDK.pause = false;
            getInstance().stopThread();
            ActionAsSDK.getInstance().init(getApplicationContext());
            ActionNormalSDK.getInstance().wakeUp(this);
            EventBus.getDefault().post(new TopTipBean(getString(R.string.mb29)));
            SDK.isRunning = true;
            NoticManager.getInstance().show(NoticEnum.RunningNotic);
            if (FloatUtil.getShowFlow(this) && FloatUtil.getHideFloat(this)) {
                this.mSetFlagRun = "set";
                YYFloatButton.hide();
            }
            getInstance().startThread("auto", autoBean, null, i, i2);
            return;
        }
        ClickUtils.onlyVibrate(getContext());
        ToastUtil.warning("部分动作需要VIP才支持执行！");
    }

    private boolean findVIPAction(AutoBean autoBean) {
        List<ActionBean> searchByID = ActionBeanSqlUtil.getInstance().searchByID(autoBean.getAutoID());
        if (searchByID.size() <= 0) {
            return false;
        }
        for (ActionBean actionBean : searchByID) {
            if (findEnum(actionBean.getActionType()).isVip()) {
                return true;
            }
        }
        return false;
    }

    private Constants.ActionEnum findEnum(String str) {
        Constants.ActionEnum[] values = Constants.ActionEnum.values();
        for (Constants.ActionEnum actionEnum : values) {
            if (actionEnum.getType().equals(str)) {
                return actionEnum;
            }
        }
        return null;
    }

    private void pauseAuto() {
        SDK.pause = true;
        LogUtil.d(TAG, "暂停自动化");
        getInstance().pauseThread();
        if (this.mTypeNowRun == 101) {
            if (mAutoBeanNowRun != null) {
                EventBus eventBus = EventBus.getDefault();
                eventBus.post(new TopTipBean("暂停中：" + mAutoBeanNowRun.getAutoName()));
            }
        } else if (this.mActionBeanNowRun != null) {
            EventBus eventBus2 = EventBus.getDefault();
            eventBus2.post(new TopTipBean("暂停中：" + this.mActionBeanNowRun.getActionName()));
        }
    }

    private void resumeAuto() {
        SDK.pause = false;
        LogUtil.d(TAG, "恢复自动化");
        getInstance().resumeThread();
        if (this.mTypeNowRun == 101) {
            if (mAutoBeanNowRun != null) {
                EventBus eventBus = EventBus.getDefault();
                eventBus.post(new TopTipBean("恢复执行：" + mAutoBeanNowRun.getAutoName()));
            }
        } else if (this.mActionBeanNowRun != null) {
            EventBus eventBus2 = EventBus.getDefault();
            eventBus2.post(new TopTipBean("恢复执行：" + this.mActionBeanNowRun.getActionName()));
        }
    }

    private void startAction(ActionBean actionBean, int i, int i2) {
        SDK.pause = false;
        getInstance().stopThread();
        ActionAsSDK.getInstance().init(getApplicationContext());
        ActionNormalSDK.getInstance().wakeUp(this);
        EventBus.getDefault().post(new TopTipBean(getString(R.string.mb29)));
        SDK.isRunning = true;
        NoticManager.getInstance().show(NoticEnum.RunningNotic);
        if (FloatUtil.getShowFlow(this) && FloatUtil.getHideFloat(this)) {
            this.mSetFlagRun = "set";
            YYFloatButton.hide();
        }
        getInstance().startThread("action", null, actionBean, i, i2);
    }

    private void startActionList(ActionBean actionBean, int i, int i2) {
        SDK.pause = false;
        getInstance().stopThread();
        ActionAsSDK.getInstance().init(getApplicationContext());
        ActionNormalSDK.getInstance().wakeUp(this);
        EventBus.getDefault().post(new TopTipBean(getString(R.string.mb29)));
        SDK.isRunning = true;
        if (FloatUtil.getShowFlow(this) && FloatUtil.getHideFloat(this)) {
            this.mSetFlagRun = "set";
            YYFloatButton.hide();
        }
        getInstance().startThread("actionlist", null, actionBean, i, i2);
    }

    private void stopAutoRun() {
        stopTimerRun();
        SDK.pause = false;
        LogUtil.d(TAG, "停止自动化11111");
        try {
            ClickUtils.Click(this);
            ToastUtil.info(getString(R.string.hstt));
            SDK.isRunning = false;
            if (isRunningHand) {
                isRunningHand = false;
                FloatManager.show(InitFloatBean.FloatType.hand);
            }
            if (isRunningHandPlus) {
                isRunningHandPlus = false;
                int nowHandPlusNum = DataUtil.getNowHandPlusNum(getContext());
                for (int i = 0; i < nowHandPlusNum; i++) {
                    FloatUtil.setShowFlowClickPlus(getContext(), i, true);
                }
                FloatManager.show(InitFloatBean.FloatType.handPlus);
            }
            if (isRunningTrack) {
                isRunningTrack = false;
                FloatManager.show(InitFloatBean.FloatType.track);
            }
            CirCleViewSDK.getInstance().hide();
            NormalTopViewSDK.getInstance().hide();
            TopViewSDKShort.getInstance().hide();
            TopViewSDK.getInstance().hide();
            RectViewSDK.getInstance().hide();
            PathViewSDK.getInstance().hide();
            FloatManager.hide(InitFloatBean.FloatType.pause);
            NoticManager.getInstance().hide(NoticEnum.RunningNotic);
            if (!TextUtils.isEmpty(this.mSetFlagRun)) {
                this.mSetFlagRun = null;
                YYFloatButton.show(getContext());
            }
            getInstance().stopThread();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(TopTipBean topTipBean) {
        int topTip = FloatUtil.getTopTip(this);
        if (topTip == 1) {
            if (SDK.isRunning) {
                NormalTopViewSDK.getInstance().show(getContext(), topTipBean.getTip());
            }
        } else if (topTip == 2) {
            if (SDK.isRunning) {
                TopViewSDKShort.getInstance().show(getContext(), topTipBean.getTip());
            }
        } else if (topTip == 3) {
            if (SDK.isRunning) {
                TopViewSDK.getInstance().show(getContext(), topTipBean.getTip());
            }
        } else if (topTip == 4 && SDK.isRunning) {
            EventBus.getDefault().post(new TopClickTypeBean(TopClickType.SHOW, topTipBean.getTip()));
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(CopyTextBean copyTextBean) {
        ((ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE)).setText(copyTextBean.getText());
        ToastUtil.success("文字复制成功");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(FastResultBean fastResultBean) {
        if (FloatUtil.getClickView(this)) {
            RecordSDK.getInstance();
            if (!RecordSDK.mIsRecord) {
                RectViewSDK.getInstance().show(getContext(), fastResultBean.getX(), fastResultBean.getY(), fastResultBean.getWidth(), fastResultBean.getHeight());
            } else if (RecordSDK.getInstance().isRecording()) {
                RectViewSDK.getInstance().show(getContext(), fastResultBean.getX(), fastResultBean.getY(), fastResultBean.getWidth(), fastResultBean.getHeight());
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ClickViewBean clickViewBean) {
        if (!FloatUtil.getClickView(this)) {
            return;
        }
        if (RecordSDK.mIsRecord) {
            CirCleViewSDK.getInstance().show(getContext(), clickViewBean.getX(), clickViewBean.getY(), 50);
        } else {
            CirCleViewSDK.getInstance().show(getContext(), clickViewBean.getX(), clickViewBean.getY(), 100);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(PathViewBean pathViewBean) {
        if (!FloatUtil.getClickView(this)) {
            return;
        }
        if (RecordSDK.mIsRecord) {
            PathViewSDK.getInstance().show(getContext(), pathViewBean.getPath(), 200);
        } else {
            PathViewSDK.getInstance().show(getContext(), pathViewBean.getPath(), 200);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(NoticTextBean noticTextBean) {
        AccessibilityEvent event = noticTextBean.getEvent();
        List<AutoBean> searchAllNotic = AutoBeanSqlUtil.getInstance().searchAllNotic();
        String noticText = noticTextBean.getNoticText();
        if (searchAllNotic.size() > 0) {
            for (final AutoBean autoBean : searchAllNotic) {
                if (noticText.contains(autoBean.getAutoTypeDetail()) && autoBean.getIsEnable()) {
                    if (autoBean.getAutoType().equals("notic_now")) {
                        EventBus.getDefault().post(new DoAutoBean(101, autoBean, null, 0));
                    } else if (event.getParcelableData() != null && (event.getParcelableData() instanceof Notification)) {
                        try {
                            ((Notification) event.getParcelableData()).contentIntent.send();
                            new Handler().postDelayed(new Runnable() {
                                /* class com.lmiot.xyclick.App.MyApp.AnonymousClass29 */

                                public void run() {
                                    EventBus.getDefault().post(new DoAutoBean(101, autoBean, null, 0));
                                }
                            }, 500);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(DelayEndTime delayEndTime) {
        stopTimerRun();
        this.mTimeNumRun = 0;
        int hour = delayEndTime.getHour();
        int min = delayEndTime.getMin();
        int second = delayEndTime.getSecond();
        final int i = (hour * 3600) + (min * 60) + second;
        ToastUtil.info("将在：" + hour + "小时" + min + "分" + second + "秒后停止");
        this.mTimerRun = new Timer();
        TimerTask r4 = new TimerTask() {
            /* class com.lmiot.xyclick.App.MyApp.AnonymousClass30 */

            public void run() {
                MyApp.access$1508(MyApp.this);
                if (MyApp.this.mTimeNumRun >= i && SDK.isRunning) {
                    EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                }
            }
        };
        this.mTimerTaskRun = r4;
        this.mTimerRun.schedule(r4, 1000, 1000);
    }

    private void stopTimerRun() {
        TimerTask timerTask = this.mTimerTaskRun;
        if (timerTask != null) {
            timerTask.cancel();
            this.mTimerTaskRun = null;
        }
        Timer timer = this.mTimerRun;
        if (timer != null) {
            timer.cancel();
            this.mTimerRun = null;
        }
    }

    public boolean checkLogin(Context context) {
        if (!TextUtils.isEmpty(DataUtil.getSessionID(getContext()))) {
            return false;
        }
        Intent intent = new Intent(context, LoginActivity.class);
        this.mIntent = intent;
        if (context instanceof MyApp) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(this.mIntent);
        return true;
    }

    public void loginWx() {

    }

    public void loginByPhone(Context context) {
        YYPerUtils.sd(context, "本机登录需要申请存储权限哦", new OnPerListener() {
            @Override
            public void result(boolean z, String str) {
                DataUtil.setUserID(MyApp.getContext(), "");
                PhoneUtil.getIMEI(MyApp.getContext());
                DataUtil.setLoginByWx(MyApp.getContext(), false);
                EventBus.getDefault().post(new LoginDevSuccessBean(true));
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ShowMainActivity showMainActivity) {
        LogUtil.d(TAG, "ShowMainActivity");
        try {
            if (Build.VERSION.SDK_INT >= 29) {
                bring2Front();
                return;
            }
            Intent intent = new Intent(getContext(), MainActivity.class);
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getContext().startActivity(this.mIntent);
        } catch (Exception e) {
            e.printStackTrace();
            Intent intent2 = new Intent(getContext(), MainActivity.class);
            this.mIntent = intent2;
            intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getContext().startActivity(this.mIntent);
        }
    }

    private void bring2Front() {
        boolean z;
        ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        Iterator<ActivityManager.RunningTaskInfo> it = activityManager.getRunningTasks(3).iterator();
        while (true) {
            z = true;
            if (!it.hasNext()) {
                z = false;
                break;
            }
            ActivityManager.RunningTaskInfo next = it.next();
            if (getPackageName().equals(next.topActivity.getPackageName())) {
                String className = next.topActivity.getClassName();
                if (!className.contains("YYScreenCutActivity") && !className.contains("YYColorPickerActivity") && !className.contains("YYTrackLibActivity")) {
                    activityManager.moveTaskToFront(next.id, ActivityManager.MOVE_TASK_WITH_HOME);
                    break;
                }
            }
        }
        if (!z) {
            Intent intent = new Intent(getContext(), MainActivity.class);
            this.mIntent = intent;
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getContext().startActivity(this.mIntent);
        }
    }

    private void registNetWord() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        NetWorkReceiver netWorkReceiver = new NetWorkReceiver();
        this.mNetWorkReceiver = netWorkReceiver;
        mContext.registerReceiver(netWorkReceiver, intentFilter);
    }

    public class NetWorkReceiver extends BroadcastReceiver {
        private NetWorkReceiver() {
        }

        public void onReceive(Context context, Intent intent) {
            int netWorkState = NetworkUtils.getNetWorkState(context);
            if (netWorkState == -1) {
                EventBus.getDefault().post(new NetStateBean(NetStateBean.NetType.NONE));
            } else if (netWorkState == 0) {
                EventBus.getDefault().post(new NetStateBean(NetStateBean.NetType.Data));
            } else if (netWorkState == 1) {
                EventBus.getDefault().post(new NetStateBean(NetStateBean.NetType.WIFI));
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(NetStateBean netStateBean) {
        ToastUtil.err("netStateBean");
        int i = netStateBean.getNetType().ordinal();
    }
}
